package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.search.SearchFeignClient;
import com.atguigu.gmall.search.vo.SearchParamVo;
import com.atguigu.gmall.search.vo.SearchResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @author:ahang
 * @create:2022-10-12 20:00
 * @Description:
 */
@Controller
public class SearchController {

    @Autowired
    SearchFeignClient searchFeignClient;

    /**
     * 检索查询
     * @param paramVo
     * @return
     */
    @GetMapping("/list.html")
    public String searchListPage(SearchParamVo paramVo, Model model){
        Result<SearchResponseVo> search = searchFeignClient.search(paramVo);
        SearchResponseVo searchData = search.getData();

        model.addAttribute("searchParam",searchData.getSearchParam());
        model.addAttribute("trademarkParam",searchData.getTrademarkParam());
        model.addAttribute("trademarkList",searchData.getTrademarkList());
        model.addAttribute("propsParamList",searchData.getPropsParamList());
        model.addAttribute("attrsList",searchData.getAttrsList());
        model.addAttribute("orderMap",searchData.getOrderMap());
        model.addAttribute("goodsList",searchData.getGoodsList());
        model.addAttribute("pageNo",searchData.getPageNo());
        model.addAttribute("urlParam",searchData.getUrlParam());
        model.addAttribute("totalPages",searchData.getTotalPages());


        return "list/index";
    }
}
